package com.server;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;



import com.base.BaseController;
import com.bean.Accountmanager;
import com.dao.AccountmanagerDao;
import com.google.gson.Gson;

public class AccountManagerServer extends BaseController {
	static Logger log = Logger.getLogger(AccountManagerServer.class);
	
	AccountmanagerDao accountmanagerDao;
	@SuppressWarnings("unchecked")
	public void queryAccount(HttpServletRequest request, HttpServletResponse response) throws IOException {
		HashMap<String,Object> retMap = new HashMap<String,Object>();
		String hql = "from Accountmanager ";
		String size = request.getParameter("size");
		String page = request.getParameter("page");
		
		int from = (Integer.valueOf(page)-1)*Integer.valueOf(size);
		
		List<Accountmanager> list = accountmanagerDao.listByHQL(hql, from, Integer.valueOf(size));
		long total = accountmanagerDao.getCount(hql);
		retMap.put("total", String.valueOf(total));
		retMap.put("result", list);
		retMap.put("page", page);
		
		Gson gson = new Gson();
		String retString = gson.toJson(retMap);
		response.getWriter().print(retString);
	}
	public AccountmanagerDao getAccountmanagerDao() {
		return accountmanagerDao;
	}
	public void setAccountmanagerDao(AccountmanagerDao accountmanagerDao) {
		this.accountmanagerDao = accountmanagerDao;
	}
}
